package com.example.exp5;

import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    Button show = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.layout);
        show = findViewById(R.id.show);
        registerForContextMenu(show);
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
//            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
//            return insets;
//        });
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getMenuInflater().inflate(R.menu.custommenu, menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.custommenu, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onContextItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();

        if (itemId == R.id.create) {
            Toast.makeText(MainActivity.this, "创建群组", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.addFriend) {
            Toast.makeText(MainActivity.this, "添加朋友", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.scan) {

            Toast.makeText(MainActivity.this, "扫描二维码", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.payReceive) {

            Toast.makeText(MainActivity.this, "接收付款", Toast.LENGTH_SHORT).show();
            return true;
        } else {
            return super.onContextItemSelected(item);
        }
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();

        if (itemId == R.id.create) {
            Toast.makeText(MainActivity.this, "创建群组", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.addFriend) {
            Toast.makeText(MainActivity.this, "添加朋友", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.scan) {

            Toast.makeText(MainActivity.this, "扫描二维码", Toast.LENGTH_SHORT).show();
            return true;
        } else if (itemId == R.id.payReceive) {

            Toast.makeText(MainActivity.this, "接收付款", Toast.LENGTH_SHORT).show();
            return true;
        } else {
            return super.onContextItemSelected(item);
        }
    }
}